package com.aspose.cells;

import java.util.ArrayList;

public class PivotItem {
   PivotItemCollection a;
   int b;
   int c;
   String d;
   PivotField e;
   private int j;
   boolean f;
   boolean g;
   boolean h;
   Object i;

   PivotItem(PivotItemCollection pivotItems) {
      this.a = pivotItems;
      this.b = 0;
      this.j = -1;
   }

   /** @deprecated */
   public void hide(boolean value) {
      this.setHidden(value);
   }

   public boolean isHidden() {
      return this.b(1);
   }

   public void setHidden(boolean value) {
      this.a(value, 1);
   }

   public void setPosition(int value) {
      int var2 = this.e();
      int var3 = value;
      if (value < 0) {
         var3 = 0;
      }

      if (var3 >= this.a.getCount()) {
         var3 = this.a.getCount() - 1;
      }

      this.move(var3 - var2);
   }

   public void setPositionInSameParentNode(int value) {
      int var2 = this.e();
      int var3 = value;
      int var4 = this.a.a.getPosition();
      if (var4 == 0) {
         this.move(value);
      } else {
         int var5 = this.a.a.m;
         ArrayList var6 = null;
         if (var5 == 1) {
            var6 = this.a.a.k.a.b.g;
         }

         if (var5 == 2) {
            var6 = this.a.a.k.a.b.h;
         }

         if (var6 != null && var6.size() != 0 && ((int[])((int[])var6.get(0))).length >= 4 + var4 + 1) {
            int var7 = -1;
            int var8 = 4 + var4 - 1;
            ArrayList var9 = new ArrayList();
            int var10 = var6.size();
            Object var11 = null;

            int[] var16;
            for(int var12 = 0; var12 < var10; ++var12) {
               var16 = (int[])((int[])var6.get(var12));
               if (var16[4 + var4] == var2) {
                  var7 = var16[var8];
                  com.aspose.cells.b.a.a.ze.a(var9, (Object)var7);
               } else {
                  com.aspose.cells.b.a.a.ze.a(var9, (Object)var16[var8]);
               }
            }

            if (var7 != -1) {
               if (var9.size() == 1) {
                  this.move(value);
               } else {
                  ArrayList var17 = new ArrayList();
                  boolean var13 = false;

                  int var14;
                  for(var14 = 0; var14 < var10; ++var14) {
                     var16 = (int[])((int[])var6.get(var14));
                     if (var16[var8] == var7) {
                        if (var2 == var16[4 + var4]) {
                           int var18 = var17.size();
                        }

                        com.aspose.cells.b.a.a.ze.a(var17, (Object)var16[4 + var4]);
                     }
                  }

                  if (value < 0) {
                     var3 = 0;
                  }

                  if (var3 >= var17.size()) {
                     var3 = var17.size() - 1;
                  }

                  var14 = (Integer)var17.get(var3);
                  int var15 = var14 - var2;
                  if (var15 > 0) {
                     this.a.a(var2, var14);
                  } else {
                     this.a.b(var2, var14);
                  }

               }
            }
         }
      }
   }

   public void move(int count, boolean isSameParent) {
      if (isSameParent) {
         this.a(count);
      } else {
         this.move(count);
      }

   }

   void a(int var1) {
      int var2 = this.a.a.getPosition();
      if (var2 == 0) {
         this.move(var1);
      } else {
         int var3 = this.a.a.m;
         ArrayList var4 = null;
         if (var3 == 1) {
            var4 = this.a.a.k.a.b.g;
         }

         if (var3 == 2) {
            var4 = this.a.a.k.a.b.h;
         }

         if (var4 != null && var4.size() != 0 && ((int[])((int[])var4.get(0))).length >= 4 + var2 + 1) {
            int var5 = this.e();
            int var6 = -1;
            int var7 = 4 + var2 - 1;
            ArrayList var8 = new ArrayList();
            int var9 = var4.size();
            Object var10 = null;

            int[] var15;
            for(int var11 = 0; var11 < var9; ++var11) {
               var15 = (int[])((int[])var4.get(var11));
               if (var15[4 + var2] == var5) {
                  var6 = var15[var7];
                  com.aspose.cells.b.a.a.ze.a(var8, (Object)var6);
               } else {
                  com.aspose.cells.b.a.a.ze.a(var8, (Object)var15[var7]);
               }
            }

            if (var6 != -1) {
               if (var8.size() == 1) {
                  this.move(var1);
               } else {
                  ArrayList var16 = new ArrayList();
                  int var12 = 0;

                  for(int var13 = 0; var13 < var9; ++var13) {
                     var15 = (int[])((int[])var4.get(var13));
                     if (var15[var7] == var6) {
                        if (var5 == var15[4 + var2]) {
                           var12 = var16.size();
                        }

                        com.aspose.cells.b.a.a.ze.a(var16, (Object)var15[4 + var2]);
                     }
                  }

                  int var10000 = var12 + var1;
                  int var14;
                  if (var1 > 0) {
                     var14 = var12 + var1;
                     if (var14 < 0) {
                        var14 = 0;
                     }

                     if (var14 >= var16.size()) {
                        var14 = var16.size() - 1;
                     }

                     this.a.a(var5, (Integer)var16.get(var14));
                  } else {
                     var14 = var12 + var1;
                     if (var14 >= var16.size()) {
                        var14 = var16.size() - 1;
                     }

                     if (var14 < 0) {
                        var14 = 0;
                     }

                     this.a.b(var5, (Integer)var16.get(var14));
                  }

               }
            }
         }
      }
   }

   /** @deprecated */
   public void move(int count) {
      int var2 = this.e() + count;
      int var3;
      int var4;
      if (count > 0) {
         var3 = this.e();
         var4 = this.e() + count;
         if (var4 < 0) {
            var4 = 0;
         }

         if (var4 >= this.a.getCount()) {
            var4 = this.a.getCount() - 1;
         }

         this.a.a(var3, var4);
      } else {
         var3 = this.e();
         var4 = var3 + count;
         if (var4 >= this.a.getCount()) {
            var4 = this.a.getCount() - 1;
         }

         if (var4 < 0) {
            var4 = 0;
         }

         this.a.b(var3, var4);
      }

   }

   boolean a() {
      return this.b(2);
   }

   void a(boolean var1) {
      this.a(var1, 2);
   }

   boolean b() {
      return this.b(8);
   }

   void b(boolean var1) {
      this.a(var1, 8);
   }

   boolean c() {
      return this.b(16);
   }

   void c(boolean var1) {
      this.a(var1, 16);
   }

   boolean b(int var1) {
      return (this.c & '\uffff' & var1) != 0;
   }

   void a(boolean var1, int var2) {
      this.c &= ~var2;
      this.c |= var1 ? var2 : 0;
   }

   zbqs d() {
      return this.a.a.h;
   }

   public String getStringValue() {
      Object var1 = this.getValue();
      return var1 == null ? "" : com.aspose.cells.b.a.zr.a(var1);
   }

   public double getDoubleValue() {
      Object var1 = this.getValue();
      if (var1 == null) {
         return 0.0D;
      } else if (var1 instanceof Double) {
         return (Double)var1;
      } else if (var1 instanceof Integer) {
         return (double)(Integer)var1;
      } else {
         return var1 instanceof DateTime ? CellsHelper.getDoubleFromDateTime((DateTime)var1, false) : 0.0D;
      }
   }

   public DateTime getDateTimeValue() {
      Object var1 = this.getValue();
      if (var1 == null) {
         return DateTime.a;
      } else if (var1 instanceof DateTime) {
         return (DateTime)var1;
      } else if (var1 instanceof Double) {
         return CellsHelper.getDateTimeFromDouble((Double)((Double)var1), false);
      } else {
         return var1 instanceof Integer ? CellsHelper.getDateTimeFromDouble((double)(Integer)((Integer)var1), false) : DateTime.a;
      }
   }

   public Object getValue() {
      if (this.d() != null && this.d().j != null && this.d().j.d != null && this.j < this.d().j.d.size() && this.d().j.d.get(this.j) != null) {
         return ((zbmb)this.d().j.d.get(this.j)).a;
      } else {
         return this.d() != null && this.d().c != null && this.j < this.d().c.size() && this.d().c.get(this.j) != null ? ((zbmb)this.d().c.get(this.j)).a : null;
      }
   }

   public String getName() {
      if (this.d == null) {
         if (this.getIndex() == -1) {
            this.d = this.a.a.a.b.getGrandTotalName();
            if (this.d == null) {
               return "Grand Total";
            }
         }

         if (this.d().n()) {
            return this.d().j != null && this.d().j.d != null && this.d().j.d.get(this.getIndex()) != null ? com.aspose.cells.b.a.zr.a(((zbmb)this.d().j.d.get(this.j)).a) : null;
         } else {
            return this.d().c != null && this.d().c.get(this.getIndex()) != null && ((zbmb)((zbmb)this.d().c.get(this.getIndex()))).a != null ? com.aspose.cells.b.a.zr.a(((zbmb)((zbmb)this.d().c.get(this.getIndex()))).a) : null;
         }
      } else {
         return this.d;
      }
   }

   public int getIndex() {
      return this.j;
   }

   public void setIndex(int value) {
      this.j = value;
   }

   int e() {
      return this.a.b(this);
   }
}
